package com.way.demo.test;


import java.util.Scanner;

/**
 * @author lipingwei
 * @create 2023-08-14 22:17
 */
public class mainTest3 {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        int m = in.nextInt();
        int n = in.nextInt();
        int[][] parkingStatus = new int[m][n];
        int[][] monitorStatus = new int[m][n];
        for(int i = 0;i < m;i++){
            for(int j=0;j<n;j++){
                parkingStatus[i][j] = in.nextInt();
                monitorStatus[i][j] = 0;
            }
        }

        for(int i = 0;i<m;i++){
            for(int j = 0;j<n;j++){
                if(parkingStatus[i][j] == 1){
                    monitorStatus[i][j] = 1;
                    //左侧添加摄像头
                    if(j>0){
                        monitorStatus[i][j-1] =1;
                    }
                    //右侧
                    if(j<n-1){
                        monitorStatus[i][j+1] =1;
                    }
                    if(i<m-1){
                        monitorStatus[i+1][j] =1;
                    }
                    if(i>0){
                        monitorStatus[i-1][j] =1;
                    }
                }
            }
        }
        int count=0;
        for(int i = 0;i<m;i++){
            for(int j=0;j<n;j++){
                if(monitorStatus[i][j]==1){
                    count++;
                }
            }
        }
        System.out.println(count);
    }









}
